/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * recordSearch.java
 *
 * Created on Sep 16, 2010, 1:21:49 PM
 */

package COMIC_BOOK_STORE;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;


/**
 *
 * @author DeKNOR
 */
public class BOOK_RECORD extends javax.swing.JFrame {

    Connection con;
    Statement stat;
     private DefaultListModel List;
     String tab = "\t";
     ResultSet rset;

    /** Creates new form recordSearch */
    public BOOK_RECORD() throws SQLException {
        super("DISPLAY INFORMATION");
        initComponents();
        this.setLocationRelativeTo(null);
        connect();
        populateData();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        recordSearch = new javax.swing.JLabel();
        ADDBUTTON = new javax.swing.JButton();
        BACKBUTTON = new javax.swing.JButton();
        mainMenuButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        bookList = new javax.swing.JList();
        DELETEBUTTON = new javax.swing.JButton();
        codeLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        recordSearch.setText("BOOK RECORD");
        recordSearch.setBounds(40, 20, 120, 20);
        jLayeredPane1.add(recordSearch, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ADDBUTTON.setText("ADD");
        ADDBUTTON.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ADDBUTTONActionPerformed(evt);
            }
        });
        ADDBUTTON.setBounds(660, 150, 140, 40);
        jLayeredPane1.add(ADDBUTTON, javax.swing.JLayeredPane.DEFAULT_LAYER);

        BACKBUTTON.setText("BACK");
        BACKBUTTON.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BACKBUTTONActionPerformed(evt);
            }
        });
        BACKBUTTON.setBounds(660, 250, 140, 40);
        jLayeredPane1.add(BACKBUTTON, javax.swing.JLayeredPane.DEFAULT_LAYER);

        mainMenuButton.setText("MAIN MENU");
        mainMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mainMenuButtonActionPerformed(evt);
            }
        });
        mainMenuButton.setBounds(660, 300, 140, 40);
        jLayeredPane1.add(mainMenuButton, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator1.setBounds(40, 50, 380, 10);
        jLayeredPane1.add(jSeparator1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        bookList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { " " };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(bookList);

        jScrollPane1.setBounds(40, 80, 510, 350);
        jLayeredPane1.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DELETEBUTTON.setText("DELETE");
        DELETEBUTTON.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DELETEBUTTONActionPerformed(evt);
            }
        });
        DELETEBUTTON.setBounds(660, 200, 140, 40);
        jLayeredPane1.add(DELETEBUTTON, javax.swing.JLayeredPane.DEFAULT_LAYER);

        codeLabel.setText("Book Code");
        codeLabel.setBounds(40, 50, 80, 30);
        jLayeredPane1.add(codeLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel1.setText("Book Cost");
        jLabel1.setBounds(160, 50, 80, 30);
        jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setText("Book Title");
        jLabel2.setBounds(390, 50, 110, 30);
        jLayeredPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel3.setText("Book Charge");
        jLabel3.setBounds(270, 50, 90, 30);
        jLayeredPane1.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGE_REPOSITORY/Background5 copy.jpg"))); // NOI18N
        jLabel4.setText("jLabel4");
        jLabel4.setBounds(-40, 0, 940, 500);
        jLayeredPane1.add(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 900, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                        

    private void mainMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
        new MAIN_MENU().setVisible(true);
        this.setVisible(false);
}                                              

    private void BACKBUTTONActionPerformed(java.awt.event.ActionEvent evt) {                                           
        new ADMIN_CONSOLE().setVisible(true);
        this.setVisible(false);
}                                          

    private void ADDBUTTONActionPerformed(java.awt.event.ActionEvent evt) {                                          
        try {
            new BOOK_ADD().setVisible(true);
        } catch (SQLException ex) {
            Logger.getLogger(BOOK_RECORD.class.getName()).log(Level.SEVERE, null, ex);
        }

          this.setVisible(false);// TODO add your handling code here:
    }                                         

    private void DELETEBUTTONActionPerformed(java.awt.event.ActionEvent evt) {                                             
        try {
            new BOOK_DELETE().setVisible(true); // TODO add your handling code here:
        } catch (SQLException ex) {
            Logger.getLogger(BOOK_RECORD.class.getName()).log(Level.SEVERE, null, ex);
        }

          this.setVisible(false);
    }                                            


   private void populateData() throws SQLException
    {
        String query = "SELECT * FROM BOOK ORDER BY BOOK_CODE ASC";
        List = new DefaultListModel();
        stat = con.createStatement();
        rset = stat.executeQuery(query);
        while(rset.next())
        {
            List.addElement(rset.getString("BOOK_CODE")+"                        "+tab+ rset.getString("BOOK_COST")+"                        "+tab+ rset.getString("BOOK_CHARGE") +"                        "+tab+ rset.getString("BOOK_TITLE"));
        }
        bookList.setModel(List);
    }

    private void connect() throws SQLException
    {
        DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
        System.out.println("Driver Loaded");
        con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","javaproject","javaproject");
        System.out.println("Database Connected");

    }
    /**
    * @param args the command line arguments
    */
     public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new BOOK_RECORD().setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(BOOK_RECORD.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton ADDBUTTON;
    private javax.swing.JButton BACKBUTTON;
    private javax.swing.JButton DELETEBUTTON;
    private javax.swing.JList bookList;
    private javax.swing.JLabel codeLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton mainMenuButton;
    private javax.swing.JLabel recordSearch;
    // End of variables declaration                   

}
